/**
 * 详情页面
 */

$().ready(function() {
    validateRule();
});

$.validator.setDefaults({
    submitHandler : function() {
        update();
    }
});

function update() {
    var url = ctx +"module/shop/bangAdmin";
    $.ajax({
        cache : true,
        type : "POST",
        url : url,
        data : $('#signupForm').serialize(),// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            if (data.code == 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);

            } else {
                parent.layer.alert(data.msg)
            }
        }
    });
}


//商品总分类选择事件
function selectProductType(){
    var keywords = $("#keywords").val();
    if(keywords==""){
        return;
    }

    $.ajax({
        type: "POST",
        url: ctx +"module/shop/searchUserList",
        data: {
            keywords:keywords
        },
        dataType:'json',
        cache: false,
        success: function(data){
            var data = JSON.stringify(data);
            var dataJson = JSON.parse(data);
            if(dataJson.code == "00"){
                var datas = dataJson.data;
                var count = dataJson.count;
                $("#admin_user_id").html("");
                if(count > 0){
                    for(var index in datas) {
                        var user_id = datas[index].id;
                        var nick_name = datas[index].nickName;
                        var str = "<option value=\""+user_id+"\" >"+nick_name+"</option>";
                        $("#admin_user_id").append(str);
                    }
                }else{
                    var str = "<option value=\"\" selected=\"selected\">----无----</option>";
                    $("#admin_user_id").append(str);
                }
            }
        }
    });
}



function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules : {
            sort : {
                required : true
            }
        },
        messages : {
            sort : {
                required : icon + "请输入索引"
            }
        }
    })
}